package com.isoftstone.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.isoftstone.entity.CK_Prescription;
import com.isoftstone.entity.C_Medicine;
import com.isoftstone.entity.C_Prescription;
import com.isoftstone.entity.Inpesction_item;
import com.isoftstone.entity.Patient;
import com.isoftstone.entity.Register;
import com.isoftstone.entity.W_Medicine;
import com.isoftstone.entity.W_Prescription;
import com.isoftstone.service.DocService;

@Controller
public class DocController {
	
	@Autowired
	private DocService service;
//	@RequestMapping("uncheck")
//	public String uncheck(){
//		return "docStation/TCM";
//	}
	@RequestMapping("getAllpatient")
	public String getAllpatient(ModelMap modelMap){
		List<Patient> patientList=service.getAllpatient();
		modelMap.addAttribute("patientList",patientList);	
		return "docStation/TCM";
	}
	
	@RequestMapping("TCM")
	public String getpatientById(ModelMap modelMap,String guahao_id){
//		String guahao_id="320320";
		PageHelper.startPage(1,10);
		//pageNum代表当前页码，pageSize代表每页显示条数
	
		Patient patient=service.getpatientById(guahao_id);
		Register register = service.getRegisterById(guahao_id);
		List<C_Medicine> c_medicine = service.getAllCM();
			PageInfo<C_Medicine>  page  =new PageInfo<C_Medicine>(c_medicine);
		
		List<C_Prescription> c_prescription=service.getAllCPById(guahao_id);
		System.out.println(c_prescription);
		
		modelMap.addAttribute("patient",patient);
		modelMap.addAttribute("register",register);
		modelMap.addAttribute("c_medicine",c_medicine);
		modelMap.addAttribute("page",page);
		modelMap.addAttribute("c_prescription",c_prescription);
		return "docStation/TCM";
	}
	@RequestMapping("WM")
	public String getpatientById2(ModelMap modelMap,String guahao_id){
		
		PageHelper.startPage(1,10);
		Patient patient=service.getpatientById(guahao_id);
		Register register = service.getRegisterById(guahao_id);
		List<W_Medicine> w_medicine = service.getAllWM();
		PageInfo<W_Medicine>  page  =new PageInfo<W_Medicine>(w_medicine);
		List<W_Prescription> w_prescription=service.getAllWPById(guahao_id);
		System.out.println(w_prescription);
		
		modelMap.addAttribute("patient",patient);
		modelMap.addAttribute("register",register);
		modelMap.addAttribute("w_medicine",w_medicine);
		modelMap.addAttribute("page",page);
		modelMap.addAttribute("w_prescription",w_prescription);
		return "docStation/WM";
	}
	@RequestMapping("CK")
	public String getpatientById3(ModelMap modelMap,String guahao_id){
		
		PageHelper.startPage(1,10);
		Patient patient=service.getpatientById(guahao_id);
		Register register = service.getRegisterById(guahao_id);
		List<Inpesction_item> inpesction_item = service.getAllCK();
		PageInfo<Inpesction_item>  page  =new PageInfo<Inpesction_item>(inpesction_item);
		List<CK_Prescription> ck_prescription=service.getAllCKById(guahao_id);
		System.out.println(ck_prescription);
		
		modelMap.addAttribute("patient",patient);
		modelMap.addAttribute("register",register);
		modelMap.addAttribute("page",page);
		modelMap.addAttribute("inpesction_item",inpesction_item);
		modelMap.addAttribute("ck_prescription",ck_prescription);
		return "docStation/WM";
	}
	@RequestMapping("getAllCM")
	public List<C_Medicine> getAllCM(){
		List<C_Medicine> c_medicine = service.getAllCM();
		return c_medicine;		
	}
	@RequestMapping("insertCM")
	@ResponseBody
	public boolean insertCM(String guahao_id,String cm_id,String cm_num){
		
		int cm_num0 = Integer.parseInt(cm_num); 
		
		boolean flag = service.insertCM(guahao_id,cm_id,cm_num0);
		return flag;		
	}
	@RequestMapping("deleteCM")
	@ResponseBody
	public boolean deletCM(String guahao_id,String cm_id){
		boolean flag = service.deleteCM(guahao_id,cm_id);
		return flag;		
	}
	@RequestMapping("getCMYizhu")
	@ResponseBody
	public C_Prescription getCMYizhu(String guahao_id,String cm_id){
		C_Prescription c_prescription = service.getCMYizhu(guahao_id,cm_id);
		return c_prescription;		
	}
	@RequestMapping("updateCMYizhu")
	@ResponseBody
	public boolean insertCMYizhu(String guahao_id,String cm_id,String cm_yizhu){
		boolean flag = service.updateCMYizhu(guahao_id,cm_id,cm_yizhu);
		return flag;		
	}
	
	@RequestMapping("insertWM")
	@ResponseBody
	public boolean insertWM(String guahao_id,String wm_id,String wm_num){
		int wm_num0 = Integer.parseInt(wm_num); 
		boolean flag = service.insertWM(guahao_id,wm_id,wm_num0);
		return flag;		
	}
	@RequestMapping("getWMYizhu")
	@ResponseBody
	public W_Prescription getWMYizhu(String guahao_id,String wm_id){
		W_Prescription w_prescription = service.getWMYizhu(guahao_id,wm_id);
		return w_prescription;		
	}
	@RequestMapping("updateWMYizhu")
	@ResponseBody
	public boolean insertWMYizhu(String guahao_id,String wm_id,String wm_yizhu){
		boolean flag = service.updateWMYizhu(guahao_id,wm_id,wm_yizhu);
		return flag;		
	}
	
	@RequestMapping("deleteWM")
	@ResponseBody
	public boolean deletWM(String guahao_id,String wm_id){
		boolean flag = service.deleteCM(guahao_id,wm_id);
		return flag;		
	}
	@RequestMapping("insertCK")
	@ResponseBody
	public boolean insertCK(String guahao_id,String ii_id,String ii_num){
		int ii_num0 = Integer.parseInt(ii_num); 
		boolean flag = service.insertCK(guahao_id,ii_id,ii_num0);
		return flag;		
	}
	@RequestMapping("getCKYizhu")
	@ResponseBody
	public CK_Prescription getCKYizhu(String guahao_id,String ck_id){
		CK_Prescription ck_prescription = service.getCKYizhu(guahao_id,ck_id);
		return ck_prescription;		
	}
	@RequestMapping("updateCKYizhu")
	@ResponseBody
	public boolean insertCKYizhu(String guahao_id,String ck_id,String ck_yizhu){
		boolean flag = service.updateCKYizhu(guahao_id,ck_id,ck_yizhu);
		return flag;		
	}
	@RequestMapping("deleteCK")
	@ResponseBody
	public boolean deletCK(String guahao_id,String ck_id){
		boolean flag = service.deleteCK(guahao_id,ck_id);
		return flag;		
	}
	
	
	
	@RequestMapping("searchCM")
	@ResponseBody
	public PageInfo<C_Medicine> searchCM(String cm_name,Integer pageNumber,Integer pageSize){
		PageHelper.startPage(pageNumber,pageSize);
		List<C_Medicine> c_medicine=new ArrayList<C_Medicine>();
		c_medicine=service.searchCM(cm_name);
			PageInfo<C_Medicine> page  =new PageInfo<C_Medicine>(c_medicine);
		return page;
	}
	@RequestMapping("searchWM")
	@ResponseBody
	public List<W_Medicine> searchWM(String wm_name){
		List<W_Medicine> w_medicine=new ArrayList<W_Medicine>();
		w_medicine=service.searchWM(wm_name);
		return w_medicine;
	}
	@RequestMapping("searchCK")
	@ResponseBody
	public List<Inpesction_item> searchCK(String ii_name){
		List<Inpesction_item> Inpesction_item=new ArrayList<Inpesction_item>();
		Inpesction_item=service.searchCK(ii_name);
		return Inpesction_item;
	}
}
